﻿using UnityEditor;
using UnityEngine;


namespace Super
{
	public static class GUIStyleUtil
	{
		/// <summary>
		/// 按钮不同状态，背景不同
		/// </summary>
		/// <param name="selecting"></param>
		/// <returns></returns>
		public static GUIStyle GetButtonSelectGUIStyle(bool selecting)
		{
			GUIStyle customStyle = new GUIStyle(GUI.skin.label);
			if (selecting)
			{
				Color32 color = new Color32(70, 96, 124, 255);
				customStyle.normal.background = GlobalUtil.GetSmallTexture2D(color);
			}
			else
			{
				Color32 color = new Color32(88, 88, 88, 255);
				customStyle.normal.background = GlobalUtil.GetSmallTexture2D(color);
			}
			customStyle.alignment = TextAnchor.MiddleCenter;
			customStyle.normal.textColor = Color.white;
			return customStyle;
		}

		/// <summary>
		/// 获取按钮复选框的样式
		/// </summary>
		/// <param name="state"></param>
		/// <returns></returns>
		public static Texture GetButtonCheckTexture(bool state)
		{
			if (state)
			{
				return AssetUtil.ALoadAsset<Texture>(FWConfig.editorBthCheck);
			}
			else
			{
				return GlobalUtil.GetSmallTexture2D(new Color(0, 0, 0, 0));
			}
		}

		/// <summary>
		/// 获取增加，删除的贴图。
		/// </summary>
		/// <param name="isAdd"></param>
		/// <returns></returns>
		public static Texture GetAddOrRomove(bool isAdd)
		{
			if (isAdd)
			{
				return AssetUtil.ALoadAsset<Texture>(FWConfig.editorAdd);
			}
			else
			{
				return AssetUtil.ALoadAsset<Texture>(FWConfig.editorDelete);
			}
		}

		/// <summary>
		/// 文本居中label
		/// </summary>
		/// <param name="fontSize"></param>
		/// <returns></returns>
		public static GUIStyle GetTextCenter(int fontSize)
		{
			GUIStyle customStyle = new GUIStyle(GUI.skin.label);
			customStyle.alignment = TextAnchor.MiddleCenter;
			customStyle.fontSize = fontSize;
			return customStyle;
		}

		/// <summary>
		/// 文本居中textArea
		/// </summary>
		/// <param name="fontSize"></param>
		/// <returns></returns>
		public static GUIStyle GetTextAreaCenter(int fontSize)
		{
			GUIStyle customStyle = new GUIStyle(GUI.skin.textArea);
			customStyle.alignment = TextAnchor.MiddleCenter;
			customStyle.fontSize = fontSize;
			return customStyle;
		}

		/// <summary>
		/// 折叠文本
		/// </summary>
		/// <param name="state"></param>
		/// <param name="text"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <returns></returns>
		public static bool FoldoutCenter(bool state, string text, int width = 50, int height = 50)
		{
			GUILayout.BeginHorizontal(GUILayout.Width(width));
			GUILayout.FlexibleSpace();

			GUILayout.BeginVertical(GUILayout.Height(height));
			GUILayout.FlexibleSpace();
			state = EditorGUILayout.Foldout(state, text);
			GUILayout.FlexibleSpace();
			GUILayout.EndVertical();

			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			return state;
		}
	}
}
